package com.jerry.huihome.module.home.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.jerry.huihome.R;
import com.jerry.huihome.base.BaseApplication;
import com.jerry.huihome.base.BaseViewHolder;
import com.jerry.huihome.base.MyBaseAdapter;
import com.jerry.huihome.module.home.activity.LoreDetailBannerActivity;
import com.jerry.huihome.module.home.entity.DrawHouse;
import com.nostra13.universalimageloader.core.DisplayImageOptions;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import butterknife.BindView;

/**
 * Created by LGuipeng on 2016/5/10.
 */
public class HomeBottomActivityAdapter extends MyBaseAdapter{

    private final DisplayImageOptions options;
    private final Context context;
    private DrawHouse.BodyBean.ActivitiesBean activitiesBean;

    public HomeBottomActivityAdapter(Context context, List list){
        super(context, list);
        this.context = context;
        options = BaseApplication.getApplication().getImageOptions();
    }

    @Override
    public int getLayoutId(){
        return R.layout.home_item_activity;
    }

    @Override
    public BaseViewHolder getViewHolder(){
        return new ViewHolder();
    }

    @Override
    public void bindViews(View view, BaseViewHolder viewHolder){
        activitiesBean = (DrawHouse.BodyBean.ActivitiesBean) getItem(viewHolder.position);
        ViewHolder holder = (ViewHolder) viewHolder;
        BaseApplication.getApplication().getImageLoader().
                displayImage(activitiesBean.getCoverimg(), holder.imageView,options);
        holder.imageView.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                Intent intent = new Intent(context, LoreDetailBannerActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra("address",activitiesBean.getOpenUrl());
                context.startActivity(intent);
            }
        });
        holder.tvName.setText(activitiesBean.getDigest());
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
        String date = dateFormat.format(new Date(activitiesBean.getActStartTime()));
        holder.itemTime.setText("" + date);
        holder.itemPersonCount.setText(activitiesBean.getApplyCount() + "");
        holder.itemAddress.setText(activitiesBean.getAddress());
    }

    /*@OnClick(value = R.id.iv_home_item_activity)
    public void jumpActivity(){
        Intent intent = new Intent(context, LoreDetailBannerActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra("address",activitiesBean.getOpenUrl());
        context.startActivity(intent);
    }*/

    public static class ViewHolder extends BaseViewHolder{
        @BindView(R.id.iv_home_item_activity)
        ImageView imageView;

        @BindView(R.id.tv_home_activity_item_name)
        TextView tvName;

        @BindView(R.id.rb_home_activity_item_time)
        RadioButton itemTime;

        @BindView(R.id.tv__home_activity_item_person)
        TextView itemPersonCount;

        @BindView(R.id.rb_home_activity_item_address)
        RadioButton itemAddress;
    }
}
